package com.blog.controller.frontpage;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.blog.controller.base.BaseServlet;
import com.blog.entity.ArticleDetailEntity;
import com.blog.entity.CommentContentEntity;
import com.blog.entity.PersonalcenterDetailEntity;
import com.blog.entity.UserLoginEntity;
import com.blog.service.frontpage.PersonalCenterService;

@WebServlet("/personalcenter/detail")
public class PersonalCenterDetailServlet extends BaseServlet{
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	//	PersonalcenterDetailEntity pc=null;
		UserLoginEntity user=(UserLoginEntity )req.getSession().getAttribute("user");
		int userid=user.getUser_id();
		PersonalCenterService service=PersonalCenterService .getInstance();
		Integer articleid=Integer.parseInt(req.getParameter("blogid"));
		/*String status=req.getParameter("status");
		if(status.equals("d")) {
			pc=service.getBlogDetail(1,articleid,1);
		}else {
			pc=service.getBlogDetail(1,articleid,0);
		}*/
		ArticleDetailEntity pc=service.getArticleInfo(articleid,userid);
		System.out.println(pc.getArticle_content());
		List<CommentContentEntity> coment=service.getComentById(articleid);
		req.setAttribute("blogdetail", pc);
		req.setAttribute("coment", coment);
		forward("frontpage/personalcenterdetailer");
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}
	
}